﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Nizm0.QOT
{
    /// <summary>
    /// Interaction logic for WPFTest1.xaml
    /// </summary>
    public partial class WPFTest1 : UserControl
    {
        public WPFTest1()
        {
            InitializeComponent();
            populateButtons();
        }

        public void populateButtons()
        {
            int xPos;
            int yPos;

            Random ranNum = new Random();

            for (int i = 0; i < 50; i++)
            {
                Button foo = new Button();
                Style buttonStyle = UControl.Resources["CurvedButton"] as Style;

                int sizeValue = ranNum.Next(50);

                foo.Width = sizeValue;
                foo.Height = sizeValue;

                xPos = ranNum.Next(500);
                yPos = ranNum.Next(300);

                foo.HorizontalAlignment = HorizontalAlignment.Left;
                foo.VerticalAlignment = VerticalAlignment.Top;
                foo.Margin = new Thickness(xPos, yPos, 0, 0);

                foo.Style = buttonStyle;
                foo.Name = "button" + i;

                foo.Click += new RoutedEventHandler(buttonClick);

                LayoutRoot.Children.Add(foo);
            }
        }

        private void buttonClick(object sender, EventArgs e)
        {
            Button clicked = (Button)sender;
            MessageBox.Show("Button's name is: " + clicked.Name);
        }
    }
}
